package com.jsm.tf.net.command;

import com.jsm.tf.net.message.request.ListRoomMessage;
import com.jsm.tf.net.message.response.ListRoomResponseMessage;
import com.jsm.tf.room.RoomDTO;
import com.jsm.tf.service.RoomService;
import io.netty.channel.Channel;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class ListRoomCommand implements Command<ListRoomMessage> {
    @Resource
    private RoomService roomService;

    @Override
    public void execute(ListRoomMessage message, Channel channel) {
        List<RoomDTO> roomDTOList = roomService.listRoom(message.getPage(), message.getPageSize());
        ListRoomResponseMessage listRoomResponseMessage = new ListRoomResponseMessage();
        listRoomResponseMessage.setSeq(message.getSeq());
        listRoomResponseMessage.setRoomList(roomDTOList);
        channel.writeAndFlush(listRoomResponseMessage);
    }
}
